﻿using System.Collections.Generic;
using System.ComponentModel;
using System.Web.Mvc;
using ShopB2C.Entity;

namespace xTeam.HengLe.Controller.Manage {

    public partial class MemberController : BaseController {
        /// <summary>
        /// 用户组
        /// </summary>
        public ActionResult Roles() {
            List<UserLevelEntity> roles = _rolesAccess.GetRoles();
            return View(roles);
        }
        /// <summary>
        /// 用户组
        /// </summary>
        /// <param name="i">站位的HttpPost重载</param>
        [HttpPost]
        public ActionResult Roles(int? abc) {
            string[] levleIds = Request.Form.GetValues("LevelId");
            string[] names = Request.Form.GetValues("Name");
            string[] minVals = Request.Form.GetValues("MinValue");
            string[] isDiscounts = Request.Form.GetValues("IsDiscount");
            string[] discounts = Request.Form.GetValues("Discount");

            for (int i = 0; i < levleIds.Length; i++) {
                int levleId, minVal;
                decimal discount = 0.000M;
                bool isDiscount;
                int.TryParse(levleIds[i], out levleId);
                decimal.TryParse(discounts[i], out discount);
                int.TryParse(minVals[i], out minVal);
                bool.TryParse(isDiscounts[i], out isDiscount);
                if (!string.IsNullOrEmpty(names[i]))
                    _rolesAccess.AppendRole(new UserLevelEntity() {
                        Discount = discount,
                        Icon = string.Empty,
                        IsDiscount = isDiscount,
                        LevelId = levleId,
                        MinValue = minVal,
                        Name = names[i],
                    });
            }
            return RedirectToAction("Roles");
        }
        /// <summary>
        /// 删除组
        /// </summary>
        public ActionResult DeleteRoleItem([DefaultValue(0)]int levelId) {
            _rolesAccess.RemoveRole(levelId);
            return new EmptyResult();
        }
    }
}
